package perf.data;

public class BaseCost {

	private long[] costs = null;
	private int srcline;
	
	public BaseCost() {
		
	}

	public BaseCost( long[] costs ) {
		this.costs = costs;
	}

	public int getLine( ) {
		return srcline;
	}
	
	public void setLine( int line ) {
		srcline = line;
	}
	
	public long getCost( int idx ) {
		if ( costs == null ) {
			return 0;
		} else {
			return costs[idx];
		}
	}
	
	public long[] getCosts( ) {
		return costs;
	}
	
	public void updateCosts( long[] costs ) {
		if ( this.costs != null ) {
			if ( costs.length != this.costs.length ) {
				throw new RuntimeException( "Cost arrays not of consistent length" );
			}
			for (int i = 0; i < costs.length; i++ ) {
				this.costs[i] += costs[i];
			}
		} else {
			this.costs = costs;
		}		
	}
	
	@Override
	public String toString( ) {
		StringBuffer sb = new StringBuffer();
		
		for ( long cost : costs ) {
			sb.append( cost + ", " );
		}
		
		return sb.toString();
	}
}
